package com.yeren.ams.api.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	// sessionFactory全局只需要有一个
	private static SessionFactory sessionFactory;
	static {
		Configuration cfg = new Configuration();
		cfg.configure("hibernate.cfg.xml");
		cfg.configure();// 默认读取以上的配置文件
		sessionFactory=cfg.buildSessionFactory();

	}

	// 获取全局唯一的sessionFactory
	public static SessionFactory getSessionFactory() {

		return sessionFactory;
	}

	// 从全局唯一的SessionFactory中打开一个Session
	public static Session OpenSession() {
		Session openSession = sessionFactory.openSession();
		return openSession;
	}
}
